extends Node2D

@onready var tubes: Node2D = $Tubes


var tube := preload("res://entity/tube/tube_twin.tscn")




func _process(_delta: float) -> void:
	spawn_tube()
	
func spawn_tube() -> void:
	var tube_ist := tubes.get_children()
	var separation := randi_range(0, 300)

	var end_x := -get_canvas_transform().origin.x + (get_viewport_rect().size.x / Game.game_camera.zoom.x)
	var new_pos_x := 0
	if len(tube_ist):
		var distance: float = end_x - tube_ist[len(tube_ist) - 1].global_position.x
		if distance <= 400:
			return
	
	new_pos_x = int(end_x) + separation
	var one := tube.instantiate()
	one.global_position = Vector2(new_pos_x, 0)
	get_node("/root/World/Tubes").add_child(one)
	

 
